package com.love.travel.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.love.common.datasource.annotation.Master;
import com.love.travel.domain.TravelProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.love.common.log.annotation.Log;
import com.love.common.log.enums.BusinessType;
import com.love.common.security.annotation.RequiresPermissions;
import com.love.travel.domain.TravelAttraction;
import com.love.travel.service.ITravelAttractionService;
import com.love.common.core.web.controller.BaseController;
import com.love.common.core.web.domain.AjaxResult;
import com.love.common.core.utils.poi.ExcelUtil;
import com.love.common.core.web.page.TableDataInfo;

/**
 * 旅游景点（含地区信息）Controller
 * 
 * @author love
 * @date 2025-10-15
 */
@RestController
@RequestMapping("/attraction")
public class TravelAttractionController extends BaseController
{
    @Autowired
    private ITravelAttractionService travelAttractionService;

    /**
     * 查询旅游景点（含地区信息）列表
     */
    @Master
    @RequiresPermissions("travel:attraction:list")
    @GetMapping("/list")
    public TableDataInfo list(TravelAttraction travelAttraction)
    {
        startPage();
        List<TravelAttraction> list = travelAttractionService.selectTravelAttractionList(travelAttraction);
        return getDataTable(list);
    }

    /**
     * 导出旅游景点（含地区信息）列表
     */
    @RequiresPermissions("travel:attraction:export")
    @Log(title = "旅游景点（含地区信息）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TravelAttraction travelAttraction)
    {
        List<TravelAttraction> list = travelAttractionService.selectTravelAttractionList(travelAttraction);
        ExcelUtil<TravelAttraction> util = new ExcelUtil<TravelAttraction>(TravelAttraction.class);
        util.exportExcel(response, list, "旅游景点（含地区信息）数据");
    }

    /**
     * 获取旅游景点（含地区信息）详细信息
     */
    @RequiresPermissions("travel:attraction:query")
    @GetMapping(value = "/{attractionId}")
    public AjaxResult getInfo(@PathVariable("attractionId") Long attractionId)
    {
        return success(travelAttractionService.selectTravelAttractionByAttractionId(attractionId));
    }

    /**
     * 获取旅游景点（含地区信息）详细信息
     */
    @GetMapping(value = "/getAttractions/{productId}")
    public TableDataInfo getAttractions(@PathVariable("productId") Long productId)
    {
        List<TravelAttraction> list =travelAttractionService.selectAttractionsByProductDestination(productId);
        return getDataTable(list);
    }

    /**
     * 获取旅游景点（含地区信息）详细信息
     */
    @GetMapping(value = "/getAttractionsByItineraryId/{itineraryId}")
    public TableDataInfo getAttractionsByItineraryId(@PathVariable("itineraryId") Long itineraryId)
    {
        List<TravelAttraction> list =travelAttractionService.selectAttractionsByItineraryId(itineraryId);
        return getDataTable(list);
    }

    /**
     * 新增旅游景点（含地区信息）
     */
    @RequiresPermissions("travel:attraction:add")
    @Log(title = "旅游景点（含地区信息）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TravelAttraction travelAttraction)
    {
        return toAjax(travelAttractionService.insertTravelAttraction(travelAttraction));
    }

    /**
     * 修改旅游景点（含地区信息）
     */
    @RequiresPermissions("travel:attraction:edit")
    @Log(title = "旅游景点（含地区信息）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TravelAttraction travelAttraction)
    {
        return toAjax(travelAttractionService.updateTravelAttraction(travelAttraction));
    }

    /**
     * 删除旅游景点（含地区信息）
     */
    @RequiresPermissions("travel:attraction:remove")
    @Log(title = "旅游景点（含地区信息）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{attractionIds}")
    public AjaxResult remove(@PathVariable Long[] attractionIds)
    {
        return toAjax(travelAttractionService.deleteTravelAttractionByAttractionIds(attractionIds));
    }

    /**
     * 查询省份列表，供 OpenFeign 调用
     */
    @GetMapping(value = "/getProvinces")
    public AjaxResult selectProvinces() {
        AjaxResult result = travelAttractionService.selectProvinces();
        List<HashMap<String, String>> provinces = (List<HashMap<String, String>>) result.get(AjaxResult.DATA_TAG);
        return AjaxResult.success(provinces);
    }

    /**
     * 查询城市列表，供 OpenFeign 调用
     */
    @GetMapping(value = "/getCitys/{provinceCode}")
    public AjaxResult selectCitys(@PathVariable String provinceCode) {
        AjaxResult result = travelAttractionService.selectCitys(provinceCode);
        List<HashMap<String, String>> citys = (List<HashMap<String, String>>) result.get(AjaxResult.DATA_TAG);
        return AjaxResult.success(citys);
    }
}
